home *** CD-ROM | disk | FTP | other *** search
/ Info-Mac 4 / Info_Mac IV CD-ROM (Pacific HiTech Inc.)(August 1994).iso / Development / Source / Chef 1.1 so Folder / Chef ƒ / Chef code ƒ / chef.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-02-16  |  4.5 KB  |  205 lines  |  [TEXT/KAHL]

  1. /**********************************************************************\
  2.  
  3. File:        chef.c
  4.  
  5. Purpose:    This module handles Chef initialization and a main routine
  6.             for converting text.
  7.  
  8.  
  9. Chef -=- convert text to Swedish chef talk
  10. Copyright ©1994, Mark Pilgrim
  11.  
  12. This program is free software; you can redistribute it and/or modify
  13. it under the terms of the GNU General Public License as published by
  14. the Free Software Foundation; either version 2 of the License, or
  15. (at your option) any later version.
  16.  
  17. This program is distributed in the hope that it will be useful,
  18. but WITHOUT ANY WARRANTY; without even the implied warranty of
  19. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  20. GNU General Public License for more details.
  21.  
  22. You should have received a copy of the GNU General Public License
  23. along with this program in a file named "GNU General Public License".
  24. If not, write to the Free Software Foundation, 675 Mass Ave,
  25. Cambridge, MA 02139, USA.
  26.  
  27. \**********************************************************************/
  28.  
  29. #include "chef.h"
  30. #include "chef meat.h"
  31. #include "chef files.h"
  32. #include "chef file management.h"
  33. #include "chef error.h"
  34. #include "chef progress.h"
  35. #include "program globals.h"
  36. #include "util.h"
  37. #include "msg environment.h"
  38. #include "msg menus.h"
  39.  
  40. unsigned char    gShowSaveDialog;
  41. unsigned char    gAddSuffix;
  42. unsigned char    gShowProgress;
  43. unsigned char    gUseRTF;
  44.  
  45. void InitProgram(void)
  46. {
  47.     int                i,j,k;
  48.     AppFile            myFile;
  49.     
  50.     CountAppFiles(&i, &j);
  51.     if ((j>0) && (i==0))
  52.     {
  53.         for (k=1; k<=j; k++)
  54.         {
  55.             GetAppFiles(1, &myFile);
  56.             MyMakeFSSpec(myFile.vRefNum, 0, myFile.fName, &inputFS);
  57.             StartConvert();
  58.             ClrAppFiles(k);
  59.         }
  60.     }
  61. }
  62.  
  63. void NewConvert(void)
  64. {
  65.     inputFS.name[0]=outputFS.name[0]=tempFS.name[0]=0x00;
  66.     if (GetSourceFile(&inputFS, FALSE))
  67.         StartConvert();
  68. }
  69.  
  70. void StartConvert(void)
  71. {
  72.     int                err;
  73.     Boolean            notDoneYet;
  74.     
  75.     outputFS=inputFS;
  76.     if (gAddSuffix)
  77.     {
  78.         if (outputFS.name[0]>28)
  79.             outputFS.name[0]=28;
  80.         outputFS.name[++(outputFS.name[0])]='.';
  81.         outputFS.name[++(outputFS.name[0])]='b';
  82.         outputFS.name[++(outputFS.name[0])]='o';
  83.         outputFS.name[++(outputFS.name[0])]='r';
  84.         outputFS.name[++(outputFS.name[0])]='k';
  85.     }
  86.     deleteTheThing=TRUE;
  87.     
  88.     if (gShowSaveDialog)
  89.         if (!GetDestFile(&outputFS, &deleteTheThing))
  90.             return;
  91.  
  92.     gInputNeedsUpdate=TRUE;
  93.     gOutputNeedsUpdate=FALSE;
  94.     gInputOffset=gOutputOffset=gAbsoluteOffset=0L;
  95.     
  96.     InitFiles();
  97.     HandleError(err=OpenInputFile());
  98.     if (err!=allsWell)
  99.         return;
  100.     HandleError(err=CreateTempFile());
  101.     if (err!=allsWell)
  102.     {
  103.         FinalizeFiles(FALSE);
  104.         return;
  105.     }
  106.     HandleError(err=SetupTempFile());
  107.     if (err!=allsWell)
  108.     {
  109.         FinalizeFiles(FALSE);
  110.         return;
  111.     }
  112.     
  113.     gInputBuffer=NewPtrClear(INPUT_BUFFER_MAX+16);
  114.     if (gInputBuffer==0L)
  115.     {
  116.         FinalizeFiles(FALSE);
  117.         HandleError(kNoMemory);
  118.         return;
  119.     }
  120.     
  121.     gOutputBuffer=NewPtrClear(OUTPUT_BUFFER_MAX+16);
  122.     if (gOutputBuffer==0L)
  123.     {
  124.         FinalizeFiles(FALSE);
  125.         DisposePtr(gInputBuffer);
  126.         HandleError(kNoMemory);
  127.         return;
  128.     }
  129.     
  130.     gInProgress=TRUE;
  131.     AdjustMenus();
  132.     DrawMenuBar();
  133.     
  134.     if (showThatTharProgress)
  135.     {
  136.         OpenProgressDialog(gInputLength, "\pSwedish chef");
  137.         SetProgressText("\pConverting ",inputFS.name, "\p...","\p");
  138.     }
  139.     
  140.     gInWord=gSeenI=gSeenBackslash=FALSE;
  141.     gCurlyLevel=0;
  142.     
  143.     notDoneYet=TRUE;
  144.     err=allsWell;
  145.     while ((notDoneYet) && (err==allsWell) && (gAbsoluteOffset<gInputLength))
  146.     {
  147.         if (gInputNeedsUpdate)
  148.         {
  149.             if (gInputOffset>0L)
  150.                 ShiftInputBuffer();
  151.             HandleError(err=ReadInputFile(inputRefNum, gInputBuffer+
  152.                 gWhatsReallyInInputBuffer, INPUT_BUFFER_MAX+16-gWhatsReallyInInputBuffer));
  153.             gInputNeedsUpdate=FALSE;
  154.             if (showThatTharProgress)
  155.             {
  156.                 UpdateProgressDialog(gAbsoluteOffset);
  157.                 notDoneYet=DealWithOtherPeople();
  158.             }
  159.         }
  160.         
  161.         if ((notDoneYet) && (err==allsWell) && (gOutputNeedsUpdate))
  162.         {
  163.             HandleError(err=WriteTempFile(outputRefNum, gOutputBuffer, gOutputOffset));
  164.             gOutputOffset=0L;
  165.             gOutputNeedsUpdate=FALSE;
  166.         }
  167.         
  168.         if ((notDoneYet) && (err==allsWell))
  169.             ConvertIt();
  170.     }
  171.     
  172.     if (showThatTharProgress)
  173.     {
  174.         UpdateProgressDialog(gAbsoluteOffset);
  175.         DealWithOtherPeople();
  176.     }
  177.     
  178.     if (gOutputOffset>0L)
  179.     {
  180.         HandleError(err=WriteTempFile(outputRefNum, gOutputBuffer, gOutputOffset));
  181.     }
  182.     
  183.     DisposePtr(gInputBuffer);
  184.     DisposePtr(gOutputBuffer);
  185.     
  186.     FinalizeFiles((notDoneYet) && (err==allsWell));
  187.     
  188.     if (showThatTharProgress)
  189.         DismissProgressDialog();
  190.     gInProgress=FALSE;
  191.     AdjustMenus();
  192.     DrawMenuBar();
  193. }
  194.  
  195. void ShiftInputBuffer(void)
  196. {
  197.     Mymemcpy(gInputBuffer, gInputBuffer+gInputOffset, INPUT_BUFFER_MAX+16-gInputOffset);
  198.     gWhatsReallyInInputBuffer=INPUT_BUFFER_MAX+16-gInputOffset;
  199.     gInputOffset=0L;
  200. }
  201.  
  202. void ShutDownProgram(void)
  203. {
  204. }
  205.